<template>
  <div class="article-item">
    <!-- 有图片先放图片，没有就直接放文章 找网络图片 -->
    <router-link to="/detail">
      <img v-if="articleItem.imgUrl" :src=articleItem.imgUrl alt="">
      <h4 :class="[articleItem.imgUrl ? '' : 'noimg']">{{articleItem.title}}</h4>
      <!-- 收藏的文章显示作者 -->
      <span class="author" v-if="articleItem.author"><i class="el-icon-edit"></i> {{articleItem.author}}</span>
      <p :class="[articleItem.imgUrl ? '' : 'noimg']">{{articleItem.content}}</p>
      <!-- 发表的文章显示时间 -->
      <span class="time" v-if="articleItem.createTime"><i class="el-icon-time"></i> {{articleItem.createTime}}</span>
    </router-link>
  </div>
</template>

<script>
  export default {
    name: 'ArticleItem',
    props: {
      articleItem: Object
    },
    data() {
      return {
        username: 'minus'
      }
    }
  }
</script>

<style scoped>
  .article-item {
    overflow: hidden;
    width: 200px;
    height: auto;
    background-color: #fff;
    border-radius: 5px;
    margin: 10px 40px 20px;
    padding: 10px;
    box-shadow: 1px 1px 5px #ccc;
  }

  .article-item img {
    width: 100%;
    height: 150px;
    margin-bottom: 5px;
  }

  .article-item h4 {
    font-size: 14px;
    letter-spacing: 2px;
    line-height: 18px;
    margin-left: 5px;
    margin-bottom: 3px;
    /* 多行文本溢出隐藏 */
    display: -webkit-box;
    word-break: break-all;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .article-item p {
    font-size: 12px;
    letter-spacing: 1px;
    line-height: 17px;
    text-indent: 2em;
    margin-left: 5px;
    /* 多行文本溢出隐藏 */
    display: -webkit-box;
    word-break: break-all;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: pre-line;
  }

  .article-item h4.noimg {
    -webkit-line-clamp: 3;
  }

  .article-item p.noimg {
    -webkit-line-clamp: 5;
  }

  .article-item .author {
    display: inline-block;
    color: #333;
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 1px;
    margin-bottom: 8px;
    margin-left: 5px;
  }

  .el-icon-s-check {
    font-weight: 700;
  }

  .el-icon-time {
    vertical-align: middle;
  }

  .article-item .time {
    display: inline-block;
    color: #aaa;
    font-size: 10px;
    font-weight: 400;
    margin-left: 5px;
    margin-top: 10px;
  }
</style>